<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model app\models\ThingRecordFile */

$this->title = "";
$this->params['breadcrumbs'][] = ['label' => 'CTI录音文件', 'url' => ['index']];
$this->params['breadcrumbs'][] = basename(\common\helps\Tools::getFilePath($model->Filepath),".wav");
?>
<a id="back" class="btn btn-default pull-left" href="index?page=<?php echo isset($_GET['page'])?$_GET['page']:0; ?>&per-page=<?php echo isset($_GET['per-page'])?$_GET['per-page']:0; ?>" ><i class="fa fa-backward"></i> 返回上一页</a>
<div class="help-block" style="height: 30px"></div>
<div class="thing-record-file-view">
    <h4><?= basename(\common\helps\Tools::getFilePath($model->Filepath),".wav")?></h4>
    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'ID',
            'Caller',
            'EmployeeNumber',
            'Agent',
            ['attribute'=>'TallTimeStart',
                'value'=>
                    function ($model){
                        return date('Y年m月d日 H:i:s', strtotime($model->TallTimeStart));
                    },
            ],
            ['attribute'=>'TallTimeEnd',
                'value'=>
                    function ($model){
                        return date('Y年m月d日 H:i:s', strtotime($model->TallTimeEnd));
                    },
            ],
            'Filepath',
            'HttpFilePath',
            ['attribute' => 'TallArea',
                'value' =>
                    function ($model){
                        $TallArea = $model->TallArea;
                        $TallAreaArr = explode(',',$TallArea);
                        $TallAreaStr = '';
                        foreach ($TallAreaArr as $k=>$v){
                            if($k == 0){
                                $TallAreaStr .= $v.'省-';
                            }else if($k == 1){
                                $TallAreaStr .= $v.'市';
                            }
                        }
                        return $TallAreaStr;
                    },
            ],
            ['attribute' => '分类模型',
                'value' =>
                    function($model){
                        try {
                            $result = $model->getArcProgress()->one()->arc_classify;
                            if($result==0)return '<div style="color:#dd4b39">未分类</div>';
                            $sql = "select name from arc_classify where id = $result";
                            $res = Yii::$app->db->createCommand($sql)->queryOne();
                            return '<div style="color:#00a65a">'.$res['name']."</div>";
                        }catch (Exception $e){
                            return '';
                        }
                    },
                'format' => 'raw',//表示显示的是html格式的
                'options'=>[
                    'width'=>'13%',
                ]
            ],
            ['attribute' => 'classify_status',
                'value' =>
                    function($model){
                        try {
                            $progress = $model->getArcProgress()->one()->progress;
                            if ($progress == 0){
                                return '<div style="color:#f39c12">未训练</div>';
                            }elseif ($progress == 1) {
                                return '<div style="color:#00c0ef">正在训练</div>';
                            }elseif($progress == 2) {
                                return '<div style="color:#00a65a">训练完成</div>';
                            }
                        }catch (\Exception $e){
                            return '<div style="color:#dd4b39">无状态</div>';
                        }
                    },
                'label'=>'训练状态',
                'format' => 'raw',//表示显示的是html格式的
            ],
            ['attribute' => 'arc_classify_status',
                'value' =>
                    function($model){
                        try {
                            $arc_classify_status = $model->getArcProgress()->one()->arc_classify_status;
                            if ($arc_classify_status == 2){
                                return '<div style="color:#f39c12">无情绪</div>';
                            }elseif ($arc_classify_status == 1) {
                                return '<div style="color:#00c0ef">有情绪</div>';
                            }else{
                                return '<div style="color:#dd4b39">无状态</div>';
                            }
                        }catch (\Exception $e){
                            return '<div style="color:#dd4b39">无状态</div>';
                        }
                    },
                'label'=>'情绪有无',
                'format' => 'raw',//表示显示的是html格式的
                'options'=>[
                    'width'=>'13%',
                ]
            ],
            ['attribute' => '播放',
                 'value' =>
                    function($model){
                        $Filepath = $model->Filepath;
                        $filepath = \common\helps\Tools::getFilePath($Filepath);
                        $progress = $model->getArcProgress()->one();
                        $resStr = "";
                        $Filepath = $model->Filepath;
                        $progress = $model->getArcProgress()->one();
                        $filepath = \common\helps\Tools::getFilePath($Filepath);
                        if(!empty($progress) ){
                            if($progress->progress == 4){
                                $resStr = '<a id="modal_'.$model->ID.'"
                                    style="color:#dd4b39"
                                    class="error"文件
                                    href="#"
                                    title="该文件不存在，需要到CTI中重新上传">无文件</a>&nbsp;';
                            }else{
                                $resStr = '<a id="modal_'.$model->ID.'"
                                    class="btn btn-info fa fa-play"
                                    href="../common/play-download?httpFilePath='.htmlspecialchars($filepath).'"
                                    title="请点击该机器人进行修改以及查看" data-toggle="modal"
                                    data-target="#create-modal">播放与下载</a>&nbsp;';
                            }
                        }else{
                            $resStr = '<a id="modal_'.$model->ID.'"
                                    class="btn btn-info fa fa-play"
                                    href="../common/play-download?httpFilePath='.htmlspecialchars($filepath).'"
                                    title="请点击该机器人进行修改以及查看" data-toggle="modal"
                                    data-target="#create-modal">播放与下载</a>&nbsp;';
                        }
                        return $resStr;
                        return $resStr;
                    },
                    'format' => 'raw',
            ],
            ['attribute' => 'arc_language',
                'value' =>
                    function ($model){
                        try {
                            $arcProgress = $model->getArcProgress();
                            if (!empty($arcProgress)) {
                                $progressModel = $arcProgress->one();
                                if (!empty($progressModel)) {
                                    $arcClassify = $progressModel->getArcClassify();
                                    if (!empty($arcClassify)) {
                                        $arc_classify = $arcClassify->one();
                                        $arc_problems_arr = explode('|', $arc_classify->content);
                                        $arc_language = $progressModel->arc_language;
                                        $result = \common\helps\Tools::recogniseBaiduToHtml($arc_problems_arr,$arc_language);
                                        $formatterResult = \common\helps\Tools::recogniseBaiduToHtmlFormatter($result);
                                        //将结果格式化，有。号就换行
                                        return $formatterResult;
                                    }
                                }
                            }
                        }catch (\Exception $e){
                            return '<div style="color:red">无识别结果</div>';
                        }
                    },
                'format' => 'raw',//表示显示的是html格式的
                'label'=>'识别的结果（红色<br/>标注表示为检测到的语句）：',
            ],
        ],
        // 'template' 属性调整表格每一行的样式
        'template' => '<tr><th style="width: 140px;">
        					{label}</th>
            		<td style="word-wrap:break-word;
            		word-break:break-all;
            		display: -webkit-box;-webkit-line-clamp: 10;
            		-webkit-box-orient: vertical;
            		overflow: auto;">
            		<div style="overflow:auto">
            		{value}
            		</div>
            		</td>
            		</tr>',
    ]) ?>
    <?= $this->render('/common/dialog')?>
</div>